<template>
  <div>
    <div class="top">
      <img class="Prev" @click="letGo" src="../assets/images/app_fh.png" alt />
      <div class="house_flex">
        <div>
          <img class="hand" src="../assets/images/aqyziconcs.png" alt />
        </div>
        <div class="house">安全渝中</div>
        <div class="house">版本号V{{wgtVersion}}</div>
      </div>
    </div>
    <div class="main">
      <div class="bank" @click="updata">
        检测更新
        <div class="version">
          {{wgtVersion}}
          <img class="right" src="../assets/images/appa_r.png" alt />
        </div>
      </div>
      <div class="bank" @click="Code">
        APP二维码
        <img class="right" src="../assets/images/appa_r.png" alt />
      </div>
    </div>
    <!-- 二维码弹窗 -->
    <div class="content_box" v-if="show" @click="OffCode">
      <div class="content_box_sons">
        <div>
          <img class="content_box_son_img" src="../assets/images/yzsafecs.png" alt />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      show: false,
      share: false,
      list: [],
      wgtVersion: "", //版本号
      url: "",
    };
  },
  created() {},
  mounted() {
    var that = this;
    plus.runtime.getProperty(plus.runtime.appid, function (inf) {
      // 当前版本
      that.wgtVersion = inf.version;
      console.log(inf);
    });
    //物理返回
    // window.addEventListener("popstate", function(){
    //   that.letGo();
    // }, false);
  },
  beforeCreate() {
    document.querySelector("body").setAttribute("style", "background:#E5E5E5");
  },
  beforeDestroy() {
    document.querySelector("body").setAttribute("style", "");
  },
  methods: {
    updata() {
      var that = this;
      that.axios
        .post(this.$global_msg.Url.hosted + "/showedition")
        .then((res) => {
          console.log(res.data.rows.zdgxNumber);
           that.url = res.data.rows.zdgxUrl;
          if (res.data.rows.zdgxNumber == that.wgtVersion) {
            that.$toast("没有最新版本!");
          }else{
            this.downloadWgt();
          }
        })
        .catch((err) => {});
    },
    // 下载wgt方法
    downloadWgt() {
      // 更新文件 wgt 文件地址
      var that = this;
      var wgtUrl = that.url;
      console.log(wgtUrl);
      plus.nativeUI.showWaiting("正在更新...");
      plus.downloader
        .createDownload(
          wgtUrl,
          {
            filename: "_doc/update/",
          },
          function (d, status) {
            if (status == 200) {
              console.log("下载wgt成功：" + d.filename);
              that.installWgt(d.filename); // 安装wgt方法
            } else {
              console.log("下载wgt失败！");
              plus.nativeUI.alert("下载wgt失败！");
            }
            plus.nativeUI.closeWaiting();
          }
        )
        .start();
    },
    installWgt(path) {
      plus.nativeUI.showWaiting("安装wgt文件...");
      plus.runtime.install(
        path,
        {},
        function () {
          plus.nativeUI.closeWaiting();
          console.log("安装wgt文件成功！");
          plus.nativeUI.alert("应用资源更新完成！", function () {
            plus.runtime.restart();
          });
        },
        function (e) {
          plus.nativeUI.closeWaiting();
          console.log("安装wgt文件失败[" + e.code + "]：" + e.message);
          plus.nativeUI.alert("安装wgt文件失败[" + e.code + "]：" + e.message);
        }
      );
    },
    letGo() {
      this.$router.back(); //返回上一层
    },
    Code() {
      //显示二维码
      this.show = true;
    },
    OffCode() {
      this.show = false;
    },
  },
};
</script>
<style scoped>
.top {
  height: 4.9074074074074074rem;
  background: url(../assets/images/home_bg.png) no-repeat;
  background-size: 100% 100%;
}
.Prev {
  height: 0.4267rem;
  margin-left: 0.4rem;
  padding-top: 0.6rem;
  position: relative;
  top: 0.2667rem;
}
.hand {
  width: 2rem;
  height: 2rem;
}
.house {
  font-size: 0.42592592592592593rem;
  color: #ffffff;
  /* margin-top: 0.1333rem; */
}
.house_flex {
  display: flex;
  flex-flow: column;
  align-items: center;
}
.main {
  background: #ffffff;
}
.bank {
  height: 1rem;
  background: #fff;
  font-size: 0.42592592592592593rem;
  color: #393939;
  padding-top: 0.32037037037037035rem;
  margin-left: 0.4rem;
  border-bottom: 1px solid #ccc;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.2667rem;
}
.right {
  width: 0.6667rem;
  height: 0.6667rem;
  margin-right: 0.2667rem;
}
.version {
  display: flex;
  font-size: 0.42592592592592593rem;
  color: #393939;
}
.content_box {
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  z-index: 90;
  display: flex;
}
.content_box_sons {
  width: 94%;
  height: 4.8267rem;
  margin: auto;
  z-index: 100;
  align-items: center;
  justify-content: center;
  margin-bottom: 100%;
}
.content_box_son_img {
  width: 80%;
  height: 60%;
  margin: 0 auto;
}
.content_big {
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  z-index: 90;
}
.content_big_son {
  width: 94%;
  height: 4.8267rem;
  margin: auto;
  z-index: 100;
  display: flex;
  justify-content: space-around;
  margin-top: 80%;
}
.content_big_son_img {
  width: 2rem;
  height: 2rem;
}
.wechat {
  font-size: 0.42592592592592593rem;
  color: #fff;
  text-align: center;
  margin-top: 0.2667rem;
}
</style>